package ink.ykb.droolstest.drools.dto;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import ink.ykb.droolstest.service.dto.QudaoluyouDto;
import lombok.Data;

/**
 * 优先推荐使用的渠道
 * @author dell
 *
 */
@Data
public class RetaDto  implements Serializable{
	private static final long serialVersionUID = 1L;
	
	private QudaoluyouDto qudaoluyouDto;
	private BigDecimal qudaoMinamount ;//符合规则的所有渠道最小下限金额
	private BigDecimal qudaoMaxamount ;//符合规则的所有渠道最大上限金额
	private List<QudaoluyouDto> list = new ArrayList<>();//所有匹配的渠道
	
	/**
	 * 优先匹配原则：费率最低，能贷上限金额最大，下限金额最低
	 * @return
	 */
	public List<QudaoluyouDto> sortQudaoluyouDto() {
		
		Collections.sort(list, new Comparator<QudaoluyouDto>() {

			@Override
			public int compare(QudaoluyouDto o1, QudaoluyouDto o2) {
				if(o1.getFeilv() != null && o2.getFeilv() != null ) {
					int sort = o1.getFeilv().compareTo(o2.getFeilv());
					if(sort > 0 ) {
						return 1;
					}else if(sort < 0 ) {
						return -1;
					}else {
						if(o1.getMaxamount() != null && o2.getMaxamount() != null ) {
							sort = o2.getMaxamount().compareTo(o1.getMaxamount());
							if(sort > 0 ) {
								return 1;
							}else if(sort < 0 ) {
								return -1;
							}else {
								if(o1.getMinamount() != null && o2.getMinamount() != null ) {
									sort = o1.getMinamount().compareTo(o2.getMinamount());
									if(sort > 0 ) {
										return 1;
									}else if(sort < 0 ) {
										return -1;
									}else {
										return 0;
									}
								}
							}
						}
					}
				}
				return 0;
			}
		} );
		return list;
	}
}
